<%
Class FastAsp_Cookie
    Private m_Domain     'Cookie域名
    Private m_Path       'Cookie路径
    Private m_Secure     '是否仅HTTPS
    Private m_HttpOnly   '是否仅HTTP访问
    Private m_Expires    'Cookie过期时间(分钟)
    
    Private Sub Class_Initialize()
        m_Domain = ""
        m_Path = "/"
        m_Secure = False
        m_HttpOnly = True
        m_Expires = 0
    End Sub
    
    '设置Cookie
    Public Function Set_(byval name, byval value)
        Dim cookie : Set cookie = Response.Cookies(name)
        
        '如果value是字典，则设置多级Cookie
        If TypeName(value) = "Dictionary" Then
            Dim key
            For Each key In value.Keys
                cookie(key) = value(key)
            Next
        Else
            cookie = value
        End If
        
        '设置Cookie属性
        If m_Domain <> "" Then cookie.Domain = m_Domain
        cookie.Path = m_Path
        cookie.Secure = m_Secure
        cookie.HttpOnly = m_HttpOnly
        If m_Expires > 0 Then cookie.Expires = DateAdd("n", m_Expires, Now())
        
        Set Set_ = Me
    End Function
    
    '获取Cookie
    Public Function [Get](byval name)
        If Request.Cookies(name).HasKeys Then
            '返回多级Cookie
            Dim dict : Set dict = Server.CreateObject("Scripting.Dictionary")
            Dim key
            For Each key In Request.Cookies(name)
                dict.Add key, Request.Cookies(name)(key)
            Next
            Set [Get] = dict
        Else
            [Get] = Request.Cookies(name)
        End If
    End Function
    
    '删除Cookie
    Public Function Delete(byval name)
        Response.Cookies(name).Expires = DateAdd("d", -1, Now())
        Set Delete = Me
    End Function
    
    '设置域名
    Public Function Domain(byval value)
        m_Domain = value
        Set Domain = Me
    End Function
    
    '设置路径
    Public Function Path(byval value)
        m_Path = value
        Set Path = Me
    End Function
    
    '设置是否仅HTTPS
    Public Function Secure(byval value)
        m_Secure = value
        Set Secure = Me
    End Function
    
    '设置是否仅HTTP访问
    Public Function HttpOnly(byval value)
        m_HttpOnly = value
        Set HttpOnly = Me
    End Function
    
    '设置过期时间(分钟)
    Public Function Expires(byval value)
        m_Expires = value
        Set Expires = Me
    End Function
End Class
%> 